<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>移动列表</title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css"/>
		<link rel="stylesheet" href="../../css/weui.min.css" />
		<link rel="stylesheet" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/base.css"/>
		<style>
			.mui-input-group .mui-input-row {
				height: 40px;
				min-height: 40px;
			}
			.head_div {
				background: #F0F0F0;
				height: 30px;
			}
			.head_div span {
				padding: 5px 10px;
			}
			input[type=color], input[type=date], input[type=datetime-local], input[type=datetime], input[type=email], input[type=month], input[type=number], input[type=password], input[type=search], input[type=tel], input[type=text], input[type=time], input[type=url], input[type=week], select, textarea {
				line-height: 30px;
				width: 100%;
			}
			.stuname {
				padding: 11px 0;
				line-height: 2.1;
			}
			.padding_left_10 {
				padding-left: 10px;
			}
			.padding_right_10 {
				padding-right: 10px;
			}
			.bottom_15 {
				padding-bottom: 15px;
			}
			.mui-btn-warning:enabled:active {
				color: #fff;
				border: 1px solid #18b4ed;
				background-color: #18b4ed;
			}
			.mui-btn-warning, .mui-btn-yellow {
				color: #fff;
				border: 1px solid #18b4ed;
			}
			.course_select_footer {
				width: 100%;
				height: 8%;
				position: fixed;
				bottom: 0;
				left: 0;
			}
			.next_btn {
				width: 92%;
				height: 67%;
				font-size: 16px;
				background: url(../../icon/add_research.png) no-repeat 36% 50%;
				background-size: 20px 20px;
				background-color: #18b4ed;
			}
			.change_order_div {
				height: 34px;
			}
			.change_order_div span {
				float: right;
				margin-right: 12px;
				font-size: 14px;
				padding-top: 7px
			}
			.mui-input-group .mui-input-row label~
			input {
				float: right;
				width: 85%;
				margin-bottom: 0;
				padding-left: 0;
				border: 0;
			}
			/*.mui-input-group  .mui-input-row label {
			 width: 15%;
			 }*/
			.mui-input-group  .mui-input-row label {
				width: 18%;
			}
			.mui-input-group  .mui-input-row span {
				width: 82%;
			}
			.xuanzhe-list label {
				padding-left: 40px;
				margin-top: 2px;
			}
			.quetion_tilte {
				margin-top: 2px;
			}
			.right_img {
				float: right;
				padding-left: 20px;
				background: url(../../icon/delete_xuanze.png) no-repeat 11px 50%;
				background-size: 20px 20px;
			}
			.desc {
				/*padding: 0.7rem 0.1rem;*/
				padding: 12px 15px;
				line-height: 1.1;
			}
			.question_div label {
				padding: 11px 15px;
				width: 85%;
			}
			.question_div span {
				width: 12%;
				padding: 11px 15px;
				height: 40px;
			}
			.question_div {
				border-bottom: 1px solid #d9d9d9;
			}
			.select-class-cell {
				padding: 10px;
			}
			.select-class-title {
				margin-right: 20px;
				white-space: nowrap;
				overflow: hidden;
				text-overflow: ellipsis;
			}
			.name-input[type=text] {
				padding: 10px;
			}
		</style>
	</head>
	<body>
		<div class="  base_content_font"  >
			<div class="title_div">
				<form class="  mui-input-group">
					<div class="head_div" >
						<span class="base_content_font base_dark_grey" id="Research_name">调查名称</span>
					</div>
					<div class="mui-input-row" >
						<input id="name" class="mui-navigate-right base_title_font base_black_grey name-input" type="text" placeholder=""   maxlength="20" oninput="myFunction(this)"  onkeyup="chagetext20()">
					</div>
					<!--<div class="head_div" >
						<span class="base_content_font base_dark_grey" >选择班级</span>
					</div>
					<div class="mui-input-row select-class-cell" onclick="openClass()">
						<p id="select_class" class="select-class-title base_title_font base_black_grey"></p>
						<span class="stuname mui-navigate-right span_wight base_title_font base_black_grey" ></span>
					</div>-->
					<div class="head_div" >
						<span class="base_content_font base_dark_grey  name-input" >提交成功提示语</span>
					</div>
					<div class="mui-input-row" >
						<input id="submit_toast" class="mui-navigate-right base_title_font base_black_grey name-input" type="text"  maxlength="20"  placeholder="谢谢参与！"oninput="myFunction2(this)">
					</div>
				</form>
			</div>
			<div class="change_order_div">
				<span onclick="ChangeOrder()" style="display: none" id="change_span">调整顺序</span>
			</div>
			<div class="question_list"></div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/timeStampTool.js"></script>
	<script type="text/javascript">
		var questionArr = new Array();
		var questionLen = '';
		var queArrlen = 0;
		var count = 0;
		var classarr = [];
		var className = '';
		var classid = '';
		apiready = function() {
			pageParaData();
			$("#select_class").text($api.getStorage('Research_className'));
			$("#name").val($api.getStorage('ResearchName'));
			$("#submit_toast").val($api.getStorage('Research_submit_toast'));
			$("#Research_name").text(ludongJudge() + '名称');
			if (api.pageParam.type1 == 4) {//编辑题目时
				loadDisName();
			} else if (api.pageParam.type1 = 8 || api.pageParam.type1 == 9 || api.pageParam.type1 == 7) {
				questionArr = api.pageParam.data;
				SetUI(api.pageParam.data);
				classarr = api.pageParam.classarr;
			} else {
			}
			setTimeout(function() {
				addNotifi();
			}, 500);
			 sendBuriedNotifi('0', '老师端调查创建页', '199');
		};
		function sendBuriedNotifi(busionessid, pagetype, pagetypeid) {
			var userinfo = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				uname : $api.getStorage('cfnetppusername'),
			}
			var data = {
				busionessid : busionessid,
				pagetype : pagetype,
				pagetypeid : pagetypeid,
				sourceurl : api.pageParam.sourceurl,
				sourcetitle : api.pageParam.sourcetitle,
				accesspageurl : window.location.pathname,
				accesspagetitle : document.title,
				userinfo : userinfo
			}
			SendBehaviorTrajectoriesNotifi_Study(data);
		}
		
		
		//调查名称字数不能超过30字
		function chagetext20() {
			var len = $('#name').val().length;
			if (len == 20) {
				ShowToast("调查名称最多20字");
			}
		}
		//是否是鲁东智慧课堂
		function ludongJudge() {
			//读取消息推送
			var jid = $api.getStorage('cfnetppjxid');
			if (jid != 425) {//非鲁东智能课堂
				return '调查'
			} else {
				return '投票'
			}
		}

		function loadDisName() {
			var param = {
				jid : $api.getStorage('cfnetppjxid')
			};
			cfnetppPOST(url_getZcode, param, false, function(data, status) {
				if (status == "success") {
					if (data.code == 200) {
						$('#name').val(ludongJudge() + "-" + data.zcode);
					} else {
						$('#name').val(ludongJudge() + "-" + getNowDateYue());
					}
				} else {
					$('#name').val(ludongJudge() + "-" + getNowDateYue());
				}
				var sname = $("#name").val();
				$api.setStorage('ResearchName', sname);
			});
		}

		//编辑题目时获得题目数据
		function getSurveryDetail() {
			var param = {
				id : api.pageParam.id,
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
			};
			cfnetppPOST(url_getActive, param, true, function(data, status) {
				hideProgress();
				if (status == 'success') {
					if (data.code == 200) {
						var list = data.data.question.questionitems;
						questionArr = list;
						SetUI(questionArr)
						var classlist = data.data[0].classlist;
						setupClasslist(classlist);
					}
				} else {
				}
			});
		}

		//构建班级数组
		function setupClasslist(classlist) {
			if (classlist != null && classlist.constructor == Array && classlist.length > 0) {
				classarr = classlist;
				className = '';
				classid = '';
				for (var i = 0; i < classarr.length; i++) {
					var classData = classarr[i];
					className = className + classData.name + ',';
					classid = classid + classData.id + ',';
				}
				className = className.slice(0, className.length - 1);
				classid = classid.slice(0, classid.length - 1);
			} else {
			}
		}

		function myFunction(obj) {
			$api.setStorage('ResearchName', obj.value);
		}

		function myFunction2(obj) {
			$api.setStorage('Research_submit_toast', obj.value);
		}

		function pageParaData() {
			if (api.pageParam.type1 == 4) {
				$api.setStorage('Research_className', '');
				$api.setStorage('Research_classid', '');
				$api.setStorage('ResearchName', '');
				$api.setStorage('Research_submit_toast', '');
			}
			//获取班级数组
			api.addEventListener({
				name : 'refreshClassData'
			}, function(ret, err) {
				//coding...
				if (ret.value) {
					classarr = ret.value.data;
					className = '';
					classid = '';
					for (var i = 0; i < classarr.length; i++) {
						className = className + classarr[i].name + ",";
						classid = classid + classarr[i].id + ",";
					}
					className = className.slice(0, className.length - 1);
					classid = classid.slice(0, classid.length - 1);
					$api.setStorage('Research_className', className);
					$api.setStorage('Research_classid', classid);
					$("#select_class").text(className);
				}
			});
		}

		//发送通知
		function addNotifi() {
			api.sendEvent({
				name : 'deleteQuestionNotifi',
				extra : {
					data : questionArr,
					classarr : classarr
				}
			});
		}

		//设置布局
		function SetUI(list) {
			var qxuan = '';
			var data = list;
			questionLen = data.length;
			if (questionLen > 1) {
				$('#change_span').show();
			} else {
				$('#change_span').hide();
			}
			for (var i = 0; i < questionLen; i++) {
				var questionStr = "Q" + (i + 1) + ":" + "(" + data[i].subsecttitle + ")" + data[i].titile;
				var options = data[i].options;
				$(".question_list").append('<div class="mui-input-group"  id="question_group' + i + '">' + '<div class="question_div"  onclick="editQuestion(' + i + ')">' + '<label class="top_2 font16" style=" style="width: 88%"">' + questionStr + '</label>' + '<span class="right_img " onclick="deleteQuestion(' + i + ')"></span>' + '</div>' + '<div id="item_div' + i + '" class="xuanzhe-list">' + '</div>' + '</div>');
				for (var k = 0; k < options.length; k++) {
					$("#question_group" + (i) + " .xuanzhe-list").append('<div class="mui-input-row " >' + '<label class="mui-input-row mui-checkbox mui-left">' + options[k].id + '</label>' + '<span  class="desc" >' + options[k].desc + '</span>' + '</div>');
				}
			}
		}

		//删除题目
		function deleteQuestion(index) {
			event.stopPropagation();
			var a = "#question_groquestionArrup" + index;
			$("div").remove(".question_list " + a + "");
			questionArr.splice(index, 1);
			$(".question_list").html('');
			SetUI(questionArr)
			addNotifi();
		}

		//编辑单个选项
		function editQuestion(index) {
			api.openWin({useWKWebView:true,
				name : 'Teacher_EditResearchQuestion',
				url : 'Teacher_EditResearchQuestion.html',
				pageParam : {
					data : questionArr,
					index : index,
					classarr : classarr,
					pid : api.pageParam.pid,
				cid : api.pageParam.cid,
				sourceurl : api.pageParam.sourceurl,
					sourcetitle : api.pageParam.sourcetitle
				},
				reload : true
			});
		}

		//排序
		function ChangeOrder() {
			api.openWin({useWKWebView:true,
				name : 'Teacher_ResearchChangeOrder',
				url : 'Teacher_ResearchChangeOrder.html',
				pageParam : {
					data : questionArr,
					classarr : classarr,
					openType : 16,
					pid : api.pageParam.pid,
				cid : api.pageParam.cid,
				sourceurl : api.pageParam.sourceurl,
					sourcetitle : api.pageParam.sourcetitle
				},
				slidBackEnabled : false,
				reload : true
			});
		}

		//打开选择班级
		function openClass() {
			api.openWin({useWKWebView:true,
				name : 'select_class',
				url : 'select_class.html',
				animation : {
					type : "none", //动画类型（详见动画类型常量）
					subType : "from_right", //动画子类型（详见动画子类型常量）
					duration : 200
				},
				slidBackEnabled : false,
				pageParam : {
					data : classarr,
				},
			});
		}
	</script>
</html>